home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / demos / exsyslib / examples / example3.s < prev    next >
Text File  |  1980-01-03  |  5KB  |  240 lines

  1. *****************************************************************************
  2. * 3D-Star routine - Using the 'exsys.library' startup routines...
  3. * --------------------------------------------------------------------------
  4. * This entire 3d-demo routine when using the 'exsys.library' routines takes
  5. * up only 908 bytes of diskspace UNCOMPRESSED!!!! 
  6. *****************************************************************************
  7. PlaneHeight    = 255
  8. PlaneWidth    = 40
  9. PlaneLen    = PlaneHeight*PlaneWidth
  10. PL        = PlaneLen
  11. PlaneBLTSIZE    = 3*PlaneHeight*64+(PlaneWidth/2)
  12. MaxTiefe    = $2000
  13. StarCount    = 335
  14. X        = 160
  15. Y        = 160
  16. Z        = 256
  17. ClipX        = 319
  18. ClipY        = 254
  19. movespeed    = 5
  20.  
  21.         section    example,code_c
  22.  
  23. *-------------- Were including the 'exsys.library' startup call here.
  24.  
  25.         include    'work:exsyslib/include/hardware/exsys_takeover.s'
  26.  
  27. *-------------- end of startup routine calls...
  28.  
  29.         bsr.b    InitStars
  30.         lea    NCList(pc),a0
  31.         bsr.b    newcopper
  32.         
  33. Main:        cmpi.b    #255,$dff006
  34.         bne.s    Main
  35.         bsr.w    movestars
  36.         bsr.w    ChangePlanes
  37.         btst    #6,$bfe001
  38.         bne.s    Main
  39.         rts
  40.  
  41. newcopper:    lea     $dff000,a6        ;a6=custom hardware
  42.         move.w    #$7fff,$96(a6)        ;no dma
  43.         move.l    a0,$80(a6)        ;install new copperlist ptr
  44.         clr.w    $88(a6)            ;strobe copper
  45.         move.w    #$83c0,$96(a6)        ;enable copper dma
  46.         rts
  47.  
  48. InitStars    lea    StarDatas,a0
  49.         move.w    #$1fff,d3
  50.         move.w    #StarCount-1,d7
  51. .Loop:        bsr.b    GetWord            ;X Word
  52.         add.w    #X,d2
  53.         and.w    d3,d2
  54.         sub.w    #X,d2
  55.         move.w    d2,(a0)+
  56.         bsr.b    GetWord            ;Y Word
  57.         add.w    #Y,d2
  58.         and.w    d3,d2
  59.         sub.w    #Y,d2
  60.         move.w    d2,(a0)+
  61.         bsr.b    GetWord            ;Z Word
  62.         add.w    #Z,d2
  63.         and.w    d3,d2
  64.         sub.w    #Z,d2
  65.         move.w    d2,(a0)+
  66.         dbf    d7,.Loop
  67.         lea    YTab,a0        ; calc table
  68.         moveq    #0,d0
  69.         move.w    #PlaneHeight-1,d7
  70. .Looop:        move.w    d0,(a0)+
  71.         add.w    #PlaneWidth,d0
  72.         dbra    d7,.Looop
  73.         lea    PerspTab,a1        ;build division table
  74.         move.w    #Z,d0
  75.         add.w    d0,a1
  76.         add.w    d0,a1
  77.         move.w    #Z,d2
  78.         mulu    #$7fff,d2
  79. .Loop2:        move.l    d2,d1
  80.         divu    d0,d1
  81.         move.w    d1,(a1)+
  82.         addq.w    #1,d0
  83.         cmp.w    #MaxTiefe,d0
  84.         bne.s    .Loop2
  85.         rts
  86.  
  87. GetWord:    bsr.s    GetByte
  88.         move.b    d0,d2
  89.         lsl.w    #8,d2
  90.         bsr.s    GetByte
  91.         move.b    d0,d2
  92.         rts
  93.  
  94. GetByte:    move.b    $dff007,d0
  95.         move.b    $bfd800,d1
  96.         eor.b    d1,d0
  97.         moveq    #0,d1
  98.         move.b    d0,d1
  99.         ror.b    #1,d1
  100. .loop:        dbf    d1,.loop
  101.         rts
  102.  
  103. ChangePlanes:    lea    Plane(pc),a0
  104.         movem.l    (a0),d0-d2
  105.         exg    d0,d1
  106.         exg    d1,d2
  107.         movem.l    d0-d2,(a0)
  108.         lea    PlanePtrs(pc),a0
  109.         move.w    d0,6(a0)
  110.         swap    d0
  111.         move.w    d0,2(a0)
  112.         swap    d0
  113.         add.l    #PlaneLen,d0
  114.         move.w    d0,6+8(a0)
  115.         swap    d0
  116.         move.w    d0,2+8(a0)
  117.         swap    d0
  118.         add.l    #PlaneLen,d0
  119.         move.w    d0,6+16(a0)
  120.         swap    d0
  121.         move.w    d0,2+16(a0)
  122.         swap    d0
  123.         rts
  124.  
  125. movestars    lea    $dff000,a6
  126. BlitWait    btst    #6,$02(a6)        ; wait till blitter free
  127.         bne.s    BlitWait
  128.         move.l    DelPlane(pc),$54(a6)
  129.         clr.w    $66(a6)
  130.         move.l    #$01000000,$40(a6)
  131.         move.w    #PlaneBLTSIZE,$58(a6)    ; clear screen memory
  132.         move.w    #StarCount-1,d7        ;64 Stars
  133.         lea    StarDatas,a0        ;Ptr StarDatas
  134.         lea    PerspTab,a1        ;Projection Table
  135.         movem.w    XAdd(pc),a4-a6        ;Put coordinate adds in regs
  136.         move.w    #ClipX,a3        ;Clipping constante
  137.         move.w    #ClipY,d5
  138.         move.w    #$1fff,d3
  139.         move.w    #$1000,d4        ;middle value
  140.         add.w    d4,a4            ;+x add
  141.         add.w    d4,a5            ;+y add
  142. .Loop:        movem.w    (a0),d0-d2        ;Get coordinate
  143.         add.w    a4,d0            ;add middle and de/increase x
  144.         and.w    d3,d0            ;check overflow
  145.         sub.w    d4,d0            ;sub middle
  146.         add.w    a5,d1            ;add middle and de/increase y
  147.         and.w    d3,d1            ;check overflow
  148.         sub.w    d4,d1            ;sub middle
  149.         add.w    a6,d2            ;de/increase z
  150.         and.w    d3,d2            ;check overflow
  151.         movem.w    d0-d2,(a0)        ;save coords
  152.         addq.w    #6,a0            ;(there is no movem.w d0,(a0)+)
  153. .SetStar:    cmp.w    #Z,d2            ;z<d2?
  154.         blt.s    .Next            ;-> Next star
  155.         add.w    d2,d2            ;Z*2
  156.         move.w    (a1,d2.w),d6        ;Projektionswert holen
  157.         muls    d6,d0            ;projection
  158.         swap    d0            ;
  159.         add.w    #X,d0            ;X middle of screen (160)
  160.         cmp.w    a3,d0            ;a3=ClipX (Clipping)
  161.         bhi.s    .Next            ;Don't plot
  162.         muls    d6,d1            ;projection
  163.         swap    d1
  164.         add.w    #Y,d1            ;Y middle of screen (128)
  165.         cmp.w    d5,d1            ;a4=ClipY
  166.         bhi.s    .Next            ;Don't plot
  167.         move.l    WorkPlane(pc),a2    ;plot pixel
  168.         move.w    d0,d6
  169.         lsr.w    #3,d6
  170.         add.w    d6,a2
  171.         add.w    d1,d1
  172.         move.l    a5,-(sp)
  173.         lea    YTab,a5
  174.         add.w    (a5,d1.w),a2
  175.         move.l    (sp)+,a5
  176.         not.w    d0
  177.         rol.w    #6,d2            ;get color
  178.         and.w    #$e,d2
  179.         move.w    .JT(pc,d2.w),d2
  180.         jmp    .JT(pc,d2.w)
  181.  
  182. .JT:        dc.w    .r6-.JT,.r6-.JT,.r5-.JT,.r4-.JT
  183.         dc.w    .r3-.JT,.r2-.JT,.r1-.JT,.r0-.JT
  184.  
  185. .r0:        bset    d0,(a2)            ;plot routines...
  186. .next:        dbf    d7,.Loop
  187.         rts
  188. .r1:        bset    d0,PL(a2)
  189.         dbf    d7,.Loop
  190.         rts
  191. .r2:        bset    d0,(a2)
  192.         bset    d0,PL(a2)
  193.         dbf    d7,.Loop
  194.         rts
  195. .r3:        bset    d0,PL*2(a2)
  196.         dbf    d7,.Loop
  197.         rts
  198. .r4:        bset    d0,(a2)
  199.         bset    d0,PL*2(a2)
  200.         dbf    d7,.Loop
  201.         rts
  202. .r5:        bset    d0,PL(a2)
  203.         bset    d0,PL*2(a2)
  204.         dbf    d7,.Loop
  205.         rts
  206. .r6:        bset    d0,(a2)
  207.         bset    d0,PL(a2)
  208.         bset    d0,PL*2(a2)
  209.         dbf    d7,.Loop
  210.         rts
  211.  
  212. NCList:        dc.l    $01200000,$01220000,$01240000,$01260000
  213.         dc.l    $01280000,$012a0000,$012c0000,$012e0000
  214.         dc.l    $01300000,$01320000,$01340000,$01360000
  215.         dc.l    $01380000,$013a0000,$013c0000,$013e0000
  216.         dc.l    $008e2c81,$00902bc1,$00920038,$009400d0
  217.         dc.l    $01020000,$01040000,$01080000,$010a0000
  218.         dc.l    $01000200
  219. PlanePtrs:    dc.l    $00e00000,$00e20000,$00e40000,$00e60000
  220.         dc.l    $00e80000,$00ea0000
  221.         dc.l    $01003200
  222.         dc.l    $01800000,$01820333,$01840555,$01860777
  223.         dc.l    $01880999,$018a0bbb,$018c0ddd,$018e0fff
  224.         dc.l    -2
  225.  
  226. XAdd:        dc.w    0
  227. YAdd:        dc.w    0
  228. ZAdd:        dc.w    100
  229. Plane:        dc.l    Plane1
  230. WorkPlane:    dc.l    Plane2
  231. DelPlane:    dc.l    Plane3
  232.  
  233.         section    b,bss_c
  234. Plane1:        ds.b    PlaneLen*3
  235. Plane2:        ds.b    PlaneLen*3
  236. Plane3:        ds.b    PlaneLen*3
  237. PerspTab:    ds.w    MaxTiefe
  238. StarDatas:    ds.w    StarCount*3
  239. YTab:        ds.w    PlaneHeight
  240.